<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2018/1/9
  Time: 10:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--解析表达式--%>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>注册</title>
    <script>
        $(document).ready(function () {
            $(".reg_perbut").click(function () {
                $(".reg_person").animate({left: '0'});
                $(".reg_company").animate({left: '500px'});
                $(".reg_perbut").css("display", "none");
                $(".reg_combut").css("display", "inline-block");
                $(".re_im2").css("display", "none");
                $(".re_im").css("display", "inline-block");
                $(".h42").css("display", "none");
                $(".h41").css("display", "block");
            });
            $(".reg_combut").click(function () {
                $(".reg_person").animate({left: '-500px'});
                $(".reg_company").animate({left: '0'});
                $(".reg_combut").css("display", "none");
                $(".reg_perbut").css("display", "inline-block");
                $(".re_im").css("display", "none");
                $(".re_im2").css("display", "inline-block");
                $(".h41").css("display", "none");
                $(".h42").css("display", "block");
            });
//个人注册
            $(".email_reg").click(function () {
                $(".reg_phonea").hide();
                $(".reg_emaila").show();
                $(".email_b").css("display", "inline-block");
                $(".phone_b").css("display", "none");
            });

            $(".phone_reg").click(function () {
                $(".reg_emaila").hide();
                $(".reg_phonea").show();
                $(".email_b").css("display", "none");
                $(".phone_b").css("display", "inline-block");
            });
//公司注册
            $(".email_reg2").click(function () {
                $(".reg_comphone").hide();
                $(".reg_comemail").show();
                $(".email_b2").css("display", "inline-block");
                $(".phone_b2").css("display", "none");
            });

            $(".phone_reg2").click(function () {
                $(".reg_comemail").hide();
                $(".reg_comphone").show();
                $(".email_b2").css("display", "none");
                $(".phone_b2").css("display", "inline-block");
            });
        });
    </script>
</head>


<body>
<div class="allpop" role="alert">
    <div class="all_container">
        <div class="index_tan">


            <img src="${pageContext.request.contextPath}/dist/foreEnd3/img/ren.png" alt="" class="re_im">
            <img src="${pageContext.request.contextPath}/dist/foreEnd3/img/gong.png" alt="" class="re_im2">
            <h4 style="font-size: 22px" class="h41">用户注册</h4>
            <h4 style="font-size: 22px" class="h42">企业注册</h4>
            <div class="reg_out">

                <div class="reg_person">
                    <div class="reg_ball">
                        <div class="email_r">
                            <button class="email_reg">邮箱注册</button>
                            <div class="email_b"></div>
                        </div>
                        <div class="phone_r">
                            <button class="phone_reg">手机注册</button>
                            <div class="phone_b"></div>
                        </div>
                    </div>

                    <div class="reg_emaila">
                        <form action="${pageContext.request.contextPath}/XzRegister/selEmailPc.do" method="post">
                            <div class="spe_reg">
                                <input id="email" class="reg_input" type="text" name="email" placeholder="请输入邮箱">
                                <button id="emailCode" type="button" onclick="keyEmailMember(0)" class="reg_but">获取验证码
                                </button>
                            </div>
                            <input id="idcode" class="reg_input2" type="text" name="idcode" placeholder="请输入验证码">
                            <input id="password" class="reg_input2" type="password" name="password" placeholder="请输入密码">

                            <div id="pEmailMsg" class="login_err">
                                <%--<span class="fa fa-exclamation-triangle">&nbsp;</span>--%>
                            </div>

                            <button type="button" onclick="signEmailMember()" class="login_button" style="width: 300px">
                                用户邮箱注册
                            </button>
                        </form>
                    </div>

                    <div class="reg_phonea">
                        <form action="">
                            <div class="spe_reg">
                                <input id="Mphone" class="reg_input" type="text" name="phone" placeholder="请输入手机号">
                                <button id="MpCode" type="button" onclick="keyPhone(0)" class="reg_but">获取验证码</button>
                            </div>
                            <input id="idcodePhoneMember" class="reg_input2" type="text" name="idcode"
                                   placeholder="请输入验证码">
                            <input id="passwordPhoneMember" class="reg_input2" type="password" name="password"
                                   placeholder="请输入密码">

                            <div id="MPhoneMsg" class="login_err">
                                <%--<span class="fa fa-exclamation-triangle">&nbsp;</span>--%>
                            </div>

                            <button type="button" onclick="signPhone()" class="login_button" style="width: 300px">
                                用户手机注册
                            </button>
                        </form>
                    </div>
                </div>

                <div class="reg_company">
                    <div class="reg_ball2">
                        <div class="email_r2">
                            <button class="email_reg2">邮箱注册</button>
                            <div class="email_b2"></div>
                        </div>
                        <div class="phone_r2">
                            <button class="phone_reg2">手机注册</button>
                            <div class="phone_b2"></div>
                        </div>
                    </div>

                    <div class="reg_comemail">
                        <form action="">
                            <div class="spe_reg">
                                <input id="Cemail" class="reg_input" type="text" name="email" placeholder="请输入邮箱">
                                <button id="CeCode" type="button" onclick="CkeyEmailMember(1)" class="reg_but">获取验证码
                                </button>
                            </div>
                            <input id="CEidcode" class="reg_input2" type="text" name="idcode" placeholder="请输入验证码">
                            <input id="CEpassword" class="reg_input2" type="password" name="password"
                                   placeholder="请输入密码">

                            <div id="CEmailMsg" class="login_err">
                                <%--<span class="fa fa-exclamation-triangle">&nbsp;</span>--%>
                            </div>

                            <button type="button" onclick="CsignEmailMember()" class="login_button"
                                    style="width: 300px">企业邮箱注册
                            </button>
                        </form>
                    </div>

                    <div class="reg_comphone">
                        <form action="">
                            <div class="spe_reg">
                                <input id="Cphone" class="reg_input" type="text" name="phone" placeholder="请输入手机号">
                                <button id="CpCode" type="button" onclick="CkeyPhone(1)" class="reg_but">获取验证码</button>
                            </div>
                            <input id="CPidcode" class="reg_input2" type="text" name="idcode" placeholder="请输入验证码">
                            <input id="CPpassword" class="reg_input2" type="password" name="password"
                                   placeholder="请输入密码">

                            <div id="CPhoneMsg" class="login_err">
                                <%--<span class="fa fa-exclamation-triangle">&nbsp;</span>--%>
                            </div>

                            <button type="button" onclick="CsignPhone()" class="login_button" style="width: 300px">
                                企业手机注册
                            </button>
                        </form>
                    </div>
                </div>

            </div>

            <a class="reg_perbut" style="display: none">
                <span class="fa fa-arrow-circle-right" style="color: #ffa500;display: inline-block"></span>
                切换到用户注册
            </a>
            <a class="reg_combut">
                <span class="fa fa-arrow-circle-left" style="color: #ffa500;display: inline-block"></span>
                切换到企业注册
            </a>

        </div>
        <a href="#0" class="all_close cmd_close"></a>
    </div>
</div>
</body>
<script>
    var pet;
    <%--发送邮箱验证码--%>
    function keyEmailMember(type) {
        var re = /^[\w,\.,-]*@[0-9A-Za-z]{1,20}((\.com)|(\.net)|(\.com.cn)|(\.cn)){1}$/;
        var str = document.getElementById("email").value;
        if (re.test(str)) {
            var i = 60;
            $('#emailCode').css("backgroundColor", "#aeaeae");
            $('#emailCode').attr("disabled", true);
            pet = setInterval(function () {
                i--;
                $('#emailCode').html("获取验证码(" + i + ")");
                if (i == 0) {
                    clearInterval(pet);
                    $('#emailCode').css("backgroundColor", "");
                    $('#emailCode').attr("disabled", false);
                    $('#emailCode').html("获取验证码");
                }
            }, 1000)
            $.ajax({
                url: '${pageContext.request.contextPath}/XzRegister/addEmailPc.do',
                data: {email: str, type: type},
                success: function (data) {
                    if (data.msg != "已发送") {
                        $('#pEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + data.msg);
                    }
                }
            });
        } else {
            $('#pEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '邮箱格式错误');
        }
    }


    <%--公司发送邮箱验证码--%>
    function CkeyEmailMember(type) {
        var re = /^[\w,\.,-]*@[0-9A-Za-z]{1,20}((\.com)|(\.net)|(\.com.cn)|(\.cn)){1}$/;
        var str = document.getElementById("Cemail").value;
        if (re.test(str)) {
            var i = 60;
            $('#CeCode').css("backgroundColor", "#aeaeae");
            $('#CeCode').attr("disabled", true);
            pet = setInterval(function () {
                i--;
                $('#CeCode').html("获取验证码(" + i + ")");
                if (i == 0) {
                    clearInterval(pet);
                    $('#CeCode').css("backgroundColor", "");
                    $('#CeCode').attr("disabled", false);
                    $('#CeCode').html("获取验证码");
                }
            }, 1000)
            $.ajax({
                url: '${pageContext.request.contextPath}/XzRegister/addEmailPc.do',
                data: {email: str, type: type},
                success: function (data) {
                    if (data.msg != "已发送") {
                        $('#CEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + data.msg);
                    }
                }
            });
        } else {
            $('#CEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '邮箱格式错误');
        }
    }

    //    发送手机验证码
    function keyPhone(type) {
        var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
//        var phoneReg = /^1[3|4|5|7|8][0-9]{9}$/;
        var str = document.getElementById("Mphone").value;
        if (phoneReg.test(str)) {
            var i = 60;
            $('#MpCode').css("backgroundColor", "#aeaeae");
            $('#MpCode').attr("disabled", true);
            pet = setInterval(function () {
                i--;
                $('#MpCode').html("获取验证码(" + i + ")");
                if (i == 0) {
                    clearInterval(pet);
                    $('#MpCode').css("backgroundColor", "");
                    $('#MpCode').attr("disabled", false);
                    $('#MpCode').html("获取验证码");
                }
            }, 1000)
            $.ajax({
                url: '${pageContext.request.contextPath}/XzRegister/addPhonePc.do',
                data: {phone: str, type: type},
                success: function (data) {
                    if (data.msg != "已发送") {
                        $('#MPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + data.msg);
                    }
                }
            });
        } else {
            $('#MPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '手机格式错误');
        }
    }

    //    公司发送手机验证码
    function CkeyPhone(type) {
        var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        var str = document.getElementById("Cphone").value;
        if (phoneReg.test(str)) {
            var i = 60;
            $('#CpCode').css("backgroundColor", "#aeaeae");
            $('#CpCode').attr("disabled", true);
            pet = setInterval(function () {
                i--;
                $('#CpCode').html("获取验证码(" + i + ")");
                if (i == 0) {
                    clearInterval(pet);
                    $('#CpCode').css("backgroundColor", "");
                    $('#CpCode').attr("disabled", false);
                    $('#CpCode').html("获取验证码");
                }
            }, 1000)
            $.ajax({
                url: '${pageContext.request.contextPath}/XzRegister/addPhonePc.do',
                data: {phone: str, type: type},
                success: function (data) {
                    if (data.msg != "已发送") {
                        $('#CPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + data.msg);
                    }
                }
            });
        } else {
            $('#CPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '手机格式错误');
        }
    }

    //    个人邮箱注册
    function signEmailMember() {
        var re = /^[\w,\.,-]*@[0-9A-Za-z]{1,20}((\.com)|(\.net)|(\.com.cn)|(\.cn)){1}$/;
        var email = document.getElementById("email").value;
        var password = document.getElementById("password").value;
        var idcode = document.getElementById("idcode").value;
        if (notNull(password) && notNull(idcode)) {
            if (passwordSix(password)) {
                if (re.test(email)) {
                    $.ajax({
                        url: '${pageContext.request.contextPath}/XzRegister/selEmailPc.do',
                        data: {email: email, password: password, idcode: idcode},
                        success: function (data) {
                            if (data.msg == "ok") {
                                subEmail(email, password);
                            } else {
                                $('#pEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + data.msg);
                            }
                        }
                    });
                } else {
                    $('#pEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '邮箱格式错误');
                }
            } else {
                $('#pEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '密码不得小于六位');
            }
        } else {
            $('#pEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '验证码或密码不能为空');
        }
    }

    //    企业邮箱注册
    function CsignEmailMember() {
        var re = /^[\w,\.,-]*@[0-9A-Za-z]{1,20}((\.com)|(\.net)|(\.com.cn)|(\.cn)){1}$/;
        var email = document.getElementById("Cemail").value;
        var password = document.getElementById("CEpassword").value;
        var idcode = document.getElementById("CEidcode").value;
        if (notNull(password) && notNull(idcode)) {
            if (passwordSix(password)) {
                if (re.test(email)) {
                    $.ajax({
                        url: '${pageContext.request.contextPath}/XzRegister/selEmailPc.do',
                        data: {email: email, password: password, idcode: idcode},
                        success: function (data) {
                            if (data.msg == "ok") {
                                subEmail(email, password);
                            } else {
                                $('#CEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + data.msg);
                            }
                        }
                    });
                } else {
                    $('#CEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '邮箱格式错误');
                }
            } else {
                $('#CEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '密码不得小于六位');
            }
        } else {
            $('#CEmailMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '验证码或密码不能为空');
        }
    }

    //个人手机注册
    function signPhone() {
        var re = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        var phone = document.getElementById("Mphone").value;
        var password = document.getElementById("passwordPhoneMember").value;
        var idcode = document.getElementById("idcodePhoneMember").value;
        if (notNull(password) && notNull(idcode)) {
            if (passwordSix(password)) {
                if (re.test(phone)) {
                    $.ajax({
                        url: '${pageContext.request.contextPath}/XzRegister/selPhonePc.do',
                        data: {phone: phone, password: password, idcode: idcode},
                        success: function (data) {
                            if (data.msg == "ok") {
                                subPhone(phone, idcode);
                            } else {
                                $('#MPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + 'data.msg');
                            }
                        }
                    });
                } else {
                    $('#MPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '手机格式错误');
                }
            } else {
                $('#MPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '密码不得小于六位');
            }
        } else {
            $('#MPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '验证码或密码不能为空');
        }
    }

    //企业手机注册
    function CsignPhone() {
        var re = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        var phone = document.getElementById("Cphone").value;
        var password = document.getElementById("CPpassword").value;
        var idcode = document.getElementById("CPidcode").value;
        if (notNull(password) && notNull(idcode)) {
            if (passwordSix(password)) {
                if (re.test(phone)) {
                    $.ajax({
                        url: '${pageContext.request.contextPath}/XzRegister/selPhonePc.do',
                        data: {phone: phone, password: password, idcode: idcode},
                        success: function (data) {
                            if (data.msg == "ok") {
                                subPhone(phone, idcode);
                            } else {
                                $('#CPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + 'data.msg');
                            }
                        }
                    });
                } else {
                    $('#CPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '手机格式错误');
                }
            } else {
                $('#CPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '密码不得小于六位');
            }
        } else {
            $('#CPhoneMsg').html('<span class="fa fa-exclamation-triangle">&nbsp;</span>' + '验证码或密码不能为空');
        }
    }


    function notNull(name) {
        if (name.replace(/(^s*)|(s*$)/g, "").length == 0) {
            return false;
        } else {
            return name;
        }
    }

    function passwordSix(name) {
        if (name.length < 6) {
            return false;
        } else {
            return name;
        }
    }

    function subEmail(name, password) {
        window.location.href = "${pageContext.request.contextPath}/XzLogin/Login.do?username=" + name + "&password=" + password;
    }

    function subPhone(name, password) {
        window.location.href = "${pageContext.request.contextPath}/XzLogin/LoginPhone.do?username=" + name + "&password=" + password;
    }

</script>
</html>
